package com.it.server.service.Impl;

import com.it.common.context.BaseContext;
import com.it.pojo.Entity.Dish;
import com.it.pojo.VO.DishDetailVO;
import com.it.pojo.VO.DishRotationVO;
import com.it.server.mapper.DishMapper;
import com.it.server.service.DishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishServiceImpl implements DishService {
    @Autowired
    private DishMapper dishMapper;

    @Override
    public List<DishRotationVO> rotation(Integer merchantId) {
        return dishMapper.rotation(merchantId);
    }

    @Override
    public List<Dish> list(Integer merchantId) {
       return dishMapper.list(merchantId);
    }

    @Override
    public DishDetailVO detail(Integer id) {
        Dish dish =dishMapper.detail(id);
        DishDetailVO dishDetailVO = new DishDetailVO();
        BeanUtils.copyProperties(dish,dishDetailVO);
        return dishDetailVO;
    }

    @Override
    public void add(Dish dish) {
        Long merchantId = BaseContext.getCurrentMerchantId();
        dish.setMerchantId(Integer.getInteger(merchantId+""));
        dishMapper.add(dish);
    }
}
